#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <poll.h>
#include <signal.h>
#include <unistd.h>


int main(int argc, char **argv)
{
    int fd;
    int ret;

    //默认为阻塞的方式打开
    fd = open("/dev/key0", O_RDWR);

    //以阻塞的方式打开
    //fd = open("/dev/key0", O_RDWR | O_NONBLOCK);
    if(fd < 0)
    {
        printf("can't open!\n");
        return 0;
    }

    while(1)
    {
        unsigned char key_val;
        ret = read(fd, &key_val, 1);
        printf("ret = %d key_val = %x\n", ret, key_val);
        //usleep(300000);
    }

    return 0;
}
